package com.ruoyi.teaching.service.impl;

import java.util.List;

import com.ruoyi.student.mapper.StudentMapper;
import com.ruoyi.teacher.mapper.TeacherMapper;
import com.ruoyi.teaching.domain.BblRepeate;
import com.ruoyi.teaching.dto.FocusonRepeateDto;
import com.ruoyi.teaching.mapper.BblRepeateMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.teaching.mapper.BblFocusOnMapper;
import com.ruoyi.teaching.domain.BblFocusOn;
import com.ruoyi.teaching.service.IBblFocusOnService;

/**
 * 重点关注Service业务层处理
 * lbj
 * @author ruoyi
 * @date 2023-05-19
 */
@Service
public class BblFocusOnServiceImpl implements IBblFocusOnService 
{
    @Autowired
    private BblFocusOnMapper bblFocusOnMapper;
    @Autowired
    private BblRepeateMapper bblRepeateMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private TeacherMapper teacherMapper;

    /**
     * 查询重点关注
     * 
     * @param id 重点关注主键
     * @return 重点关注
     */
    @Override
    public BblFocusOn selectBblFocusOnById(Long id)
    {
        return bblFocusOnMapper.selectBblFocusOnById(id);
    }

    /**
     * 查询重点关注列表
     * 
     * @param bblFocusOn 重点关注
     * @return 重点关注
     */
    @Override
    public List<BblFocusOn> selectBblFocusOnList(BblFocusOn bblFocusOn)
    {
        return bblFocusOnMapper.selectBblFocusOnList(bblFocusOn);
    }

    /**
     * 新增重点关注
     * 
     * @param bblFocusOn 重点关注
     * @return 结果
     */
    @Override
    public int insertBblFocusOn(BblFocusOn bblFocusOn)
    {
        return bblFocusOnMapper.insertBblFocusOn(bblFocusOn);
    }

    /**
     * 修改重点关注
     * 
     * @param bblFocusOn 重点关注
     * @return 结果
     */
    @Override
    public int updateBblFocusOn(BblFocusOn bblFocusOn)
    {
        return bblFocusOnMapper.updateBblFocusOn(bblFocusOn);
    }

    /**
     * 批量删除重点关注
     * 
     * @param ids 需要删除的重点关注主键
     * @return 结果
     */
    @Override
    public int deleteBblFocusOnByIds(Long[] ids)
    {
        return bblFocusOnMapper.deleteBblFocusOnByIds(ids);
    }

    /**
     * 删除重点关注信息
     * 
     * @param id 重点关注主键
     * @return 结果
     */
    @Override
    public int deleteBblFocusOnById(Long id)
    {
        return bblFocusOnMapper.deleteBblFocusOnById(id);
    }

    @Override
    public int addFocusonRepeate(FocusonRepeateDto dto) {

        BblFocusOn bblFocusOn = new BblFocusOn();
        BeanUtils.copyProperties(dto,bblFocusOn);
        bblFocusOnMapper.insertBblFocusOn(bblFocusOn);
//        如果开启了留级状态,将数据加入留级表
        if (dto.getIsRepeate()){
            BblRepeate bblRepeate = new BblRepeate();
            BeanUtils.copyProperties(dto,bblRepeate);
            bblRepeate.setDifficultyNumber(dto.getDifficulty());
            String stuName = studentMapper.selectStudentById(dto.getStudentId()).getName();
            bblRepeate.setStudent(stuName);
            String teaName = teacherMapper.selectTeacherById(dto.getTeacherId()).getName();
            bblRepeate.setDutyTeacher(teaName);
            bblRepeate.setRemark(dto.getNote());
            bblRepeateMapper.insertBblRepeate(bblRepeate);
        }
        return 1;
    }
}
